import Mock from 'mockjs'
var {
	pp
} = Mock.mock({
	'pp|88': [{
		'id|+1': 1,
		'ming|1': ['Internet Explorer 4.0', 'Internet Explorer 5.5', 'Camino 1.0', 'Firefox 3.0',
			'AOL browser', 'AOL desktop'
		],
		'date': '@now',
		'xing|1': ['A', 'B', 'C', 'X', 'Y', 'Z'],
		'flag|1': ['是', '否'],
	}]
})
const Getquery = (url, name) => {
	const index = url.indexOf('?')
	if (index !== -1) {
		const queryArr = url.substr(index + 1).split('&')
		for (var i = 0; i < queryArr.length; i++) {
			const itemArr = queryArr[i].split('=')
			if (itemArr[0] === name) {
				return itemArr[1]
			}
		}
	}
	return null
}
Mock.mock(/\/api\/get\/biao/, 'get', (options) => {
	const pageindex = Getquery(options.url, 'pageindex')
	const pagesize = Getquery(options.url, 'pagesize')
	const start = (pageindex - 1) * pagesize
	const end = pagesize * pageindex
	const Page = Math.ceil(pp.length / pagesize)
	const list = pageindex > Page ? [] : pp.slice(start, end)
	return {
		code: 0,
		msg: "请求成功",
		data: {
			biao: list
		},
		title: pp.length,
	}
})
var {
	GetUser
} = Mock.mock({
	'users|88': [{
		'id|+1': 1,
		'username': '@last',
		'name': '@cname',
		'bumen|1': ['安保', '研发', '销售', '管理', '设计'],
		'juese|1': ['组长', '经理', '队长']，,
		'tel|10000000000-19999999999': 18864505517,
		'duanhao': '@zip',
		'login|1': ['是', '否'],
		'yuanyin|1': ['统计', '复查', '监控', '了解'],
		'num|1-9': 1,
		'timer': '@now'
	}]
})
Mock.mock(/\/api\/get\/GetUser/, 'get', (options) => {
	const pageindex = Getquery(options.url, 'pageindex')
	const pagesize = Getquery(options.url, 'pagesize')
	const start = (pageindex - 1) * pagesize
	const end = pagesize * pageindex
	const Page = Math.ceil(pp.length / pagesize)
	const list = pageindex > Page ? [] : pp.slice(start, end)
	return {
		code: 0,
		msg: "请求成功",
		data: {
			biao: list
		},
		title: pp.length,
	}
})
